package cst.a703xmq.zyfypt_703xmq.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cst.a703xmq.zyfypt_703xmq.Activity.SVideoActivity;
import cst.a703xmq.zyfypt_703xmq.Adapter.SVideoAdapter;
import cst.a703xmq.zyfypt_703xmq.Bean.SVideoBean;
import cst.a703xmq.zyfypt_703xmq.Interface.XmqListener;
import cst.a703xmq.zyfypt_703xmq.Model.ResModel;
import cst.a703xmq.zyfypt_703xmq.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class VFragment_sv extends BaseFragment {
    private RecyclerView recyclerView;
    private SVideoAdapter adapter;
    private List<SVideoBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private XmqListener<List<SVideoBean>> svideo_listener;
    private ResModel model;
    private Context context;


    public VFragment_sv() {
        // Required empty public constructor
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        context = getActivity();

        View view = inflater.inflate(R.layout.vfragment_sv, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.svideo_rec);
        list = new ArrayList<SVideoBean>();
        layoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new SVideoAdapter(context);
        adapter.setOnItemClickListener(new SVideoAdapter.OnItemClickListener(){
            @Override
            public void onItemClick(View view, int position){
                Intent intent = new Intent(context, SVideoActivity.class);
                intent.putExtra("resid",list.get(position).getId());
                context.startActivity(intent);
            }

            @Override
            public void onItemLongClick(View view, int position){}
        });
        adapter.setList(list);
        recyclerView.setAdapter(adapter);
        svideo_listener = new XmqListener<List<SVideoBean>>() {
            @Override
            public void onResponse(List<SVideoBean> l) {
                list=l;
                adapter.setList(list);
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();

            }
        };
//        model = new ResModel("gson",getSessionID());
        model = new ResModel("gson");
        model.getList("svideo", 1,svideo_listener);

        return view;
    }
}